const flag = '[P2P Fetch]';
let debug = true;

export const logError = err => {
    if (debug) console.error(flag, err);
};

/**
 * 
 * @param {string} message
 * @param {number} level = 5
 */
export const logInfo = (...params) => {
    let level = params.length > 1 ? params.pop() : 5;
    let msg = params.map(msgObj => {
        if (msgObj instanceof Error) return `${msgObj.message}`;
        return msgObj;
    });
    if (level <= 4 && debug) console.info(flag, ...msg);
};

export const setDebug = open => {
    debug = open;
};
